
//
//  CommentCell.m
//  WGFGlobalHouses
//
//  Created by Andy on 15/7/14.
//  Copyright (c) 2015年 waiguofang. All rights reserved.
//

#import "CommentCellP.h"
#import "config.h"
#import "CommentData.h"
#import "UIButton+WebCache.h"



@interface CommentCellP ()

@property (weak, nonatomic) IBOutlet UIButton *headImgView;
@property (weak, nonatomic) IBOutlet UILabel *nickLab;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *btn1Hight;

@end


@implementation CommentCellP



+(instancetype) cellWithTableView:(UITableView *)tableview{

    static NSString *ID = @"CommentCellP";
    CommentCellP *cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"CommentCellP" owner:nil options:nil]lastObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];

        cell.commentLab.preferredMaxLayoutWidth = PMW-14-25-18;
        
        [cell.commentLab layoutIfNeeded];
    }
    
    return cell;
}


+(CGFloat)getHight:(CommentData*)data withTableView:(UITableView*)tableView{
    
    
    static CommentCellP *cell = nil;
    
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        
         cell = [CommentCellP cellWithTableView:tableView];
    });
    
    [cell setData:data];
    
    CGFloat height = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
    return height+1;
}



-(void)setData:(CommentData*)data{

    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:data.headImgPath] forState:UIControlStateNormal];
    
    [self.nickLab setText:data.nickName];
    [self.commentLab setText:data.commentDetail];
    

    if (data.imgArray.count>0) {
        self.btn1Hight.constant = 75;
        
        [self.imgBtn1  sd_setImageWithURL:[NSURL URLWithString:[data.imgArray firstObject]] forState:UIControlStateNormal];
        
        if (data.imgArray.count>1) {
            [self.imgBtn2  sd_setImageWithURL:[NSURL URLWithString:[data.imgArray objectAtIndex:1]] forState:UIControlStateNormal];
        }
        
        if (data.imgArray.count>2) {
            [self.imgBtn3  sd_setImageWithURL:[NSURL URLWithString:[data.imgArray objectAtIndex:2]] forState:UIControlStateNormal];
        }
        
    }else{
        self.btn1Hight.constant = 0;
    }
    
    
    [self.imgBtn1 layoutIfNeeded];
    [self.imgBtn2 layoutIfNeeded];
    [self.imgBtn3 layoutIfNeeded];
    
}



@end
